package com.example.finalapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class LogActivity extends Activity {
    private static final String TAG = "LogActivity";
    private SharedPreferences sharedPreferences;
    int elatedTimes,elatedTimes1,elatedTimes2,elatedTimes3,elatedTimes4,elatedTimes5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log);

//        String updateDate = sharedPreferences.getString("update_date","");
////获取当前系统时间
//        Date today = Calendar.getInstance().getTime();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        final String todayStr = sdf.format(today);
//        Log.i(TAG, "onCreate: sp updateDate=" + updateDate);
//        Log.i(TAG, "onCreate: todayStr=" + todayStr);
//
////判断时间
//        if(!todayStr.equals(updateDate)){
//            Log.i(TAG, "onCreate: 需要更新");
//
//            LogTask logTask = new LogTask();
//            Thread t = new Thread(logTask);
//            t.start();
//
//        }else{
//            Log.i(TAG, "onCreate: 不需要更新");
//        }
    }

    public void onClick(View v) {
            ImageButton elatedButton = (ImageButton) findViewById(R.id.running);
            elatedButton.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences = getSharedPreferences("times", Activity.MODE_PRIVATE);
            int e = preferences.getInt("times", 1);

            @Override
            public void onClick(View view) {
                SharedPreferences pre = getSharedPreferences("times", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = pre.edit();
                editor.putInt("times", elatedTimes++);
                editor.apply();

                AlertDialog.Builder builder = new AlertDialog.Builder(LogActivity.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行有氧运动" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times", e+1);
                editor.apply();

            }
        });
    }

    public void onClick1(View v) {

            ImageButton elatedButton1 = (ImageButton) findViewById(R.id.button_less);
            elatedButton1.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences1 = getSharedPreferences("times1", Activity.MODE_PRIVATE);
            int e = preferences1.getInt("times1", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences sp = getSharedPreferences("times1",Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt("times1", elatedTimes1++);
                editor.apply();


                AlertDialog.Builder builder = new AlertDialog.Builder(LogActivity.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行无氧运动" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times1", e+1);
                editor.apply();
            }
        });
    }
    public void onClick2(View v) {

        ImageButton elatedButton2 = (ImageButton) findViewById(R.id.button_small);
        elatedButton2.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences2 = getSharedPreferences("times2", Activity.MODE_PRIVATE);
            int e = preferences2.getInt("times2", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences pref = getSharedPreferences("times2", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = pref.edit();
                editor.putInt("times2", elatedTimes2++);
                editor.apply();


                AlertDialog.Builder builder = new AlertDialog.Builder(LogActivity.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行小球类运动" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times2", e+1);
                editor.apply();
            }

        });
    }
    public void onClick3(View v){
        ImageButton elatedButton3 = (ImageButton)findViewById(R.id.button_yoga);
        elatedButton3.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences3 = getSharedPreferences("times3", Activity.MODE_PRIVATE);
            int e = preferences3.getInt("times3", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences preff = getSharedPreferences("times3", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preff.edit();
                editor.putInt("times3", elatedTimes3++);
                editor.apply();

                AlertDialog.Builder builder = new AlertDialog.Builder(LogActivity.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行瑜伽" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times3", e+1);
                editor.apply();
            }

        });
    }

    public void onClick4(View v){
        ImageButton elatedButton4 = (ImageButton)findViewById(R.id.ring);
        elatedButton4.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences4 = getSharedPreferences("times4", Activity.MODE_PRIVATE);
            int e = preferences4.getInt("times4", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences preff = getSharedPreferences("times4", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preff.edit();
                editor.putInt("times4", elatedTimes4++);
                editor.apply();

                AlertDialog.Builder builder = new AlertDialog.Builder(LogActivity.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计早起" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times4", e+1);
                editor.apply();
            }

        });
    }

    public void onClick5(View v){
        ImageButton elatedButton5 = (ImageButton)findViewById(R.id.music);
        elatedButton5.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences5 = getSharedPreferences("times5", Activity.MODE_PRIVATE);
            int e = preferences5.getInt("times5", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences preff = getSharedPreferences("times5", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preff.edit();
                editor.putInt("times5", elatedTimes5++);
                editor.apply();

                AlertDialog.Builder builder = new AlertDialog.Builder(LogActivity.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计听音乐" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times5", e+1);
                editor.apply();
            }

        });
    }
}